package ms.platform.util;

public class PathUtil {

	/**
	 * Get classes path
	 * 
	 * @return
	 */
	public static String getWebClassesPath() {
		String path = PathUtil.class.getProtectionDomain().getCodeSource()
				.getLocation().getPath();
		return path;
	}

	/**
	 * Get WEB-INF path
	 * 
	 * @return
	 * @throws IllegalAccessException
	 */
	public static String getWebInfPath() throws IllegalAccessException {
		String path = getWebClassesPath();
		if (path.indexOf("WEB-INF") > 0) {
			path = path.substring(0, path.indexOf("WEB-INF") + 8);
		} else {
			throw new IllegalAccessException("Error path!");
		}
		return path;
	}

	/**
	 * Get root path
	 * 
	 * @return
	 * @throws IllegalAccessException
	 */
	public static String getWebRoot() throws IllegalAccessException {
		String path = getWebClassesPath();
		if (path.indexOf("WEB-INF") > 0) {
			path = path.substring(0, path.indexOf("WEB-INF/classes"));
		} else {
			throw new IllegalAccessException("Error path!");
		}
		return path;
	}

}
